External Exam Download Resources Web Applications Games Recycle Bin

CSS class vs id

.class is used to style multiple elements throughout the page or site

#id is used to style a single or unique element

htmlandcss.html

<style>

/* .class: */
.underwater {
  color: seashell;
  background-color: royalblue;
  border: 2px dashed lightblue;
}

/* #id: */    
#inthesky {
  color: lightskyblue;
  background-color: deepskyblue;
  border: 3px dotted floralwhite;
}
    
</style>

<p class="underwater">This paragraph is underwater.</p>

<p id="inthesky">This one is in the sky!</p>

<p class="underwater">Back underwater again.</p>